﻿using System;
using Lottery.App.Model;
using System.Collections.Generic;

namespace Lottery.App.DAL
{
    public class A1Dao : ResultDao<A1Info>
    {
        protected override int GetLastID(string value)
        {
            string hql = "select Max(r.id) from RecordInfo r where A1 = ?";

            return Session.CreateQuery(hql)
                .SetString(0, value)
                .UniqueResult<int>();
        }

        internal override IList<RecordInfo> List(string value)
        {
            string hql = "from RecordInfo where A1 = ?";

            return Session.CreateQuery(hql)
                .SetString(0, value)
                .List<RecordInfo>();
        }

        public override IList<int> GetIds(string value)
        {
            const string hql = "select r.id from RecordInfo r where A1 = ?";
            
            return Session.CreateQuery(hql)
                .SetString(0, value)
                .List<int>();
        }

        protected override IList<A1Info> GetItems(RecordInfo record)
        {
            const string hql = "from A1Info where Value = ?";

            return Session.CreateQuery(hql)
                .SetString(0, record.A1)
                .List<A1Info>();
        }
    }
}